/**
 * @System abcs-aspchain
 * @Description: Copyright: Copyright (c) 2018
 * Company: Aspire Technologies
 * @author zhongzifeng
 * @date 2018/12/24 10:05
 * @version V1.0
 */
package com.asp.aspchain.admin.rest;

import com.alibaba.fastjson.JSON;
import com.asp.aspchain.admin.biz.MgrNodeBiz;
import com.asp.aspchain.admin.biz.SequenceBiz;
import com.asp.aspchain.admin.entity.MgrNode;
import com.asp.aspchain.common.msg.ObjectRestResponse;
import com.asp.aspchain.common.rest.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 节点管理控制器
 * @author zhongzifeng
 * @date 2018/12/24 10:05
 *
 */
@RestController
@RequestMapping("/node")
public class MgrNodeController extends BaseController<MgrNodeBiz, MgrNode> {

    private static final Logger logger = LoggerFactory.getLogger(MgrNodeController.class);

    @Autowired
    private MgrNodeBiz mgrNodeBiz;

    @Autowired
    private SequenceBiz sequenceBiz;


    @RequestMapping(value = "/addpeer",method = RequestMethod.POST)
    @ResponseBody
    public ObjectRestResponse addPeer(@RequestBody String json){
        logger.info(json);
        MgrNode mgrNodeReq = JSON.parseObject(json, MgrNode.class);
        ObjectRestResponse<Object> response = new ObjectRestResponse<>();

        logger.info("补全数据");
        // 新增节点参数
        String nodeid = sequenceBiz.getNextStringValue("nodeid");
        mgrNodeReq.setNodeid(Integer.parseInt(nodeid));
        mgrNodeReq.setCreatetime(new Date());
        mgrNodeReq.setUpdatetime(new Date());
        // 插入数据
        mgrNodeBiz.insertSelective(mgrNodeReq);
        response.setRel(true);
        return response;
    }
}
